package com.mdp.sms.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.mdp.core.service.BaseService;
import static com.mdp.core.utils.BaseUtils.*;
import com.mdp.core.entity.Tips;
import com.mdp.core.err.BizException;

import com.mdp.sms.entity.SmsReply;
import com.mdp.sms.mapper.SmsReplyMapper;
/**
 * @author maimeng-mdp code-gen
 * @since 2024-3-6
 */
@Service
public class SmsReplyService extends BaseService<SmsReplyMapper,SmsReply> {
	static Logger logger =LoggerFactory.getLogger(SmsReplyService.class);

	/**
	 * 自定义查询，支持多表关联
	 * @param page 分页条件
	 * @param ew 一定要，并且必须加@Param("ew")注解
	 * @param ext 如果xml中需要根据某些值进行特殊处理，可以通过这个进行传递，非必须，注解也可以不加
	 * @return
	 */
	public List<Map<String,Object>> selectListMapByWhere(IPage page, QueryWrapper ew, Map<String,Object> ext){
		return baseMapper.selectListMapByWhere(page,ew,ext);
	}
	/**
	 * 腾讯云的短信回复的回调接口
	 * https://cloud.tencent.com/document/product/382/5809
	 * @cdate 2019/9/18 20:58
	 * @author lyk
	 */
	public void tcSmsReplyCallBack(HashMap<String, Object> params) {
		String extend=(String)params.get("extend");
		String mobile=(String)params.get("mobile");
		String nationcode=(String)params.get("nationcode");
		String sign=(String)params.get("sign");
		String text=(String)params.get("text");
		Number time=(Number)params.get("time");//传递过来的是秒
		SmsReply customerInsertSmsReplyObject=new SmsReply();
		customerInsertSmsReplyObject.setId(this.createKey("id"));
		customerInsertSmsReplyObject.setExtend(extend);
		customerInsertSmsReplyObject.setMobile(mobile);
		customerInsertSmsReplyObject.setNationcode(nationcode);
		customerInsertSmsReplyObject.setSign(sign);
		customerInsertSmsReplyObject.setText(text);
		customerInsertSmsReplyObject.setStatus("0");
		Date createDate=new Date(1000L*time.longValue());
		customerInsertSmsReplyObject.setCreateDate(createDate);
		this.insert(customerInsertSmsReplyObject);
		Map<String,Object> updateParams=new HashMap();
		updateParams.put("extend", extend);
		updateParams.put("mobile", mobile);
		updateParams.put("nationcode", nationcode);
		updateParams.put("id", customerInsertSmsReplyObject.getId());
		this.baseMapper.updateExtendNoAndFlowIdWhenUserReply(updateParams);
	}
}

